package tool

import (
	"crypto/md5"
	"encoding/hex"
	"math/rand"
	"strings"
	"time"
)

func GetPass(pass string, acode string) string {
	return getMd5(pass,acode)
}

func GetAcode() string {
	var length int = 12
	char := "abcdefghijklmnopqrstuvwxyz"
	charArr := strings.Split(char, "")
	ran := rand.New(rand.NewSource(time.Now().Unix()))

	l := len(charArr)
	for i := l - 1; i > 0; i-- {
		r := ran.Intn(i)
		charArr[r], charArr[i] = charArr[i], charArr[r]
	}
	rchar := charArr[:length]
	return strings.Join(rchar, "")
}

func getMd5(pass string, acode string) string {
	str := acode + "$$xxCC**`I1l0oOs5S~`..ERASDjkA^&*,." + pass + "@x^#^$#@@&~!@~5+-/!@."
	h := md5.New()
	h.Write([]byte(str))
	hex.EncodeToString(h.Sum(nil))
	return hex.EncodeToString(h.Sum(nil))

}
